package cn.xiuxian.rsmd;

import cn.xiuxian.util.JdbcUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

//resultset的其他用法
public class ResultSetDemo {
    public static void main(String[] args) {

        Connection  connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;

        try {
            connection = JdbcUtil.getConnection();
            String sql = "select  *  from  jdbc_video";
            preparedStatement = connection.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);

            resultSet =  preparedStatement.executeQuery();

            //resultSet.last();
            resultSet.absolute(5);
            //正数向下，负数向上
            resultSet.relative(-1);

            resultSet.beforeFirst();
            resultSet.first();
            System.out.println(resultSet.getString(2));
            System.out.println(resultSet.getRow());
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            JdbcUtil.closeConnection(connection,preparedStatement,resultSet);
        }
    }
}
